<template>
  <div class="question">
    <van-row class="question-user" type="flex" justify="start" align="center">
      <!-- 1.用户信息与发布时间 -->
      <van-col class="image" @click.stop="toUserindex">
        <van-image :src="user.image" round width="30px" height="30px"></van-image>
      </van-col>
      <!-- 2.问题title -->
      <van-col>
        <h1 class="question-title" @click="toDetail">{{topic.title}}</h1>
      </van-col>
    </van-row>
    <!-- 3.文章浏览量与评论 -->
    <div class="question-footer">{{viewcount}}浏览·{{commentcount}}评论</div>
    <!-- 4.操作选项 -->
    <div class="operation-ellipsis">
      <van-icon name="ellipsis" size="22px" @click.stop="showOperation" />
      <operation-box class="operation" direction="bottom" v-if="operate_show"></operation-box>
    </div>
  </div>
</template>

<script>
import time from "@/common/time";
import utils from "@/common/utils";
import operationbox from "../Popup/topic-operate";
export default {
  name: "question-card",
  props: {
    user: {
      type: Object,
      require: true,
    },
    topic: {
      type: Object,
      require: true,
    },
  },
  data() {
    return {
      operate_show: false,
    };
  },
  methods: {
    toDetail() {
      this.$router.push({ path: "/topic", query: { id: this.topic.id } });
    },
    toUserindex() {
      this.$router.push({
        path: "/account/userindex",
        query: { user: this.user.name },
      });
    },
    showOperation() {
      this.operate_show = true;
    },
  },
  computed: {
    time() {
      return time.timeshow(this.topic.time);
    },
    viewcount() {
      return utils.numberShow(this.topic.viewcount);
    },
    commentcount() {
      return utils.numberShow(this.topic.commentcount);
    },
  },
  mounted() {},
  components: {
    "operation-box": operationbox,
  },
};
</script>

<style>
.question {
  /* position: relative; */
  background: #fff;
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: 3px 3px 5px 0px #97979759;
}
.question-title {
  color: #646566;
  font-size: 16px;
  min-width: 80%;
  min-height: 20px;
  max-height: 50px;
  float: left;
  text-align: left;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.question-user {
  padding: 10px 10px 5px 10px;
  text-align: left;
}
.question-user .image {
  text-align: center;
  padding-right: 10px;
}
.question-footer {
  text-align: left;
  font-size: 12px;
  padding: 8px;
  color: #909090;
}
.operation-ellipsis {
  position: relative;
}
.question .van-icon {
  position: absolute;
  right: 15px;
  bottom: 10px;
  color: #4994e5;
}
/* .question .operation {
  position: absolute;
  bottom: 30px;
  right: 10px;
} */
</style>